@SETLOCAL
@ECHO OFF
REM -- Usage: Make <target>...
REM -- E.g.:  Make deb
REM --
REM -- Each <target> may be:
REM --   all		Build everything (default)
REM --   deb		Build debug version
REM --   rel		Build release version
REM --   doc		Generates documentation
REM --   getdsf		Copies documentation support files to DocFiles to simplify static file editing
REM --   ide		Open this solution in Visual Studio
REM --   run		Runs the service as a console application
REM --   install	Installs and starts the service using Service Control Manager
REM --   uninstall	Stops and uninstalls the service using Service Control Manager
REM --   clean		Delete built files
REM --   cleanall	Delete built files and IDE temporary files
REM --

REM -- location of the CodeDoc tool and its source code
SET CODEDOCSRC=..\..\CodeDoc
SET CODEDOCEXE=%CODEDOCSRC%\bin\Release\CodeDoc.exe

IF "%1"=="" Make.bat all

:loop
IF "%1"=="" EXIT /B 0
ECHO [%1]
GOTO %1

:all
CALL Make.bat deb rel
GOTO next

:deb
CALL ..\Misc\VsBuild HomeUX.sln Debug bin\Debug\HomeUX.exe
GOTO next

:rel
CALL ..\Misc\VsBuild HomeUX.sln Release bin\Release\HomeUX.exe
GOTO next

:doc
%CODEDOCEXE% CodeDoc.xml
copy /y ..\Misc\_SyncToc.htm ..\Drop\ServerDoc\Pages
GOTO next

:getdsf
copy %CODEDOCSRC%\SupportFiles\*.css DocFiles
GOTO next

:ide
CALL ..\Misc\Elevate start HomeUX.sln
GOTO next

:run
CALL ..\Misc\Elevate bin\Debug\HomeUX /Console
GOTO next

:install
..\Misc\Elevate Make.bat install2
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
GOTO next

:install2
sc create HomeUX start= auto binPath= %~dp0bin\Debug\HomeUX.exe DisplayName= HomeUX obj= "NT Authority\Network Service"
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
net start HomeUX
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
GOTO next

:uninstall
..\Misc\Elevate Make.bat uninstall2
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
GOTO next

:uninstall2
net stop HomeUX 2> nul
sc delete HomeUX
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
GOTO next

:clean
rmdir /s /q bin 2> nul
rmdir /s /q obj 2> nul
GOTO next

:cleanall
CALL Make.bat clean
del HomeUX.csproj.user 2> nul
attrib -h -r HomeUX.v11.suo > nul
del HomeUX.v11.suo 2> nul
FOR %%f IN (%CODEDOCSRC%\SupportFiles\*.css) DO del DocFiles\%%~nxf
GOTO next

:next
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
SHIFT
GOTO loop

